﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using CoolERP_BLL;
using CoolERP_Entities;

namespace CoolERP_Web.WebService
{
    /// <summary>
    /// Area 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。
    [System.Web.Script.Services.ScriptService]
    public class Area : System.Web.Services.WebService
    {
        [WebMethod]
        public string GetRegionsList(int Pid)
        {
            string json = string.Empty;
            using (RegionBLL rBLL = new RegionBLL())
            {
                List<Region> itemList = new List<Region>();
                if (Pid == 0)
                    itemList = rBLL.GetList(t => t.ParentID == null);
                else
                    itemList = rBLL.GetList(t => t.ParentID == Pid);
                foreach (Region item in itemList)
                    json = string.Concat(json, "{id:'", item.ID, "',name:'", item.Name, "'},");
            }
            if (!string.IsNullOrEmpty(json))
                json = "[" + json.Trim(',') + "]";
            return json;
        }

        [WebMethod]
        public string GetRegionsString(int id)
        {
            string areaString = string.Empty;
            using (RegionBLL rBLL = new RegionBLL())
            {
                areaString = rBLL.GetEntity(t => t.ID == id).Path;
            }
            return areaString;
        }
    }
}
